#include "CONST.h"

#import "iBlipApp.h"
#import "ViewController.h"
#import <UIKit/UIBox.h>

@implementation iBlipApp

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification 
{
	BOOL isDir = YES; 
	//it should be compatible with 1.1.2 and 1.1.3 and other firmwares
	if (![[NSFileManager defaultManager] fileExistsAtPath: PATH isDirectory: &isDir])
	{
		[[NSFileManager defaultManager] createDirectoryAtPath: PATH attributes: nil];
	} 

	NSDate * date = [NSDate date];

	NSLog(@">> Loading..");

	struct CGRect rect	=	[UIHardware fullScreenApplicationContentRect];
	rect.origin.x		=	rect.origin.y = 0.0f;
	rect.size.width = 320.0;
	rect.size.height = 460.0;
	
	_window = [[UIWindow alloc] initWithContentRect:rect];

	ViewController * vc = [ViewController initSharedInstanceWithFrame:rect];

	[_window	setContentView:	vc]; 
	[_window	orderFront:		self];
	[_window	makeKey:		self];
	[_window	_setHidden:		NO];
	
    	[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(resetIdles) userInfo:nil repeats:YES];	
}

-(void)resetIdles
{
	[self resetIdleTimer];
	[self resetIdleDuration:0.0f];
}

- (void)applicationSuspend:(struct __GSEvent *)event 
{
	NSLog(@"Suspending...");
}

- (void)applicationResume:(struct __GSEvent *)event 
{
	NSLog(@"Resuming...");
}

- (void)applicationDidResumeFromUnderLock
{
	NSLog(@"Resuming from under lock...");
}

- (void)applicationWillSuspendUnderLock
{
	if(![UIApp isLocked])
	{
		NSLog(@"Locking...");
	}
}

- (BOOL)applicationIsReadyToSuspend
{
	return NO;
}

- (BOOL)isSuspendingUnderLock
{
	return NO;
}

- (void)applicationWillTerminate 
{	
	[UIApp removeApplicationBadge];
}

- (BOOL) suspendRemainInMemory
{
	NSLog(@"suspendRemainInMemory");
	return YES;
}

@end 
